package com.yyy.controller;

import com.yyy.pojo.tb_door;
import com.yyy.service.Tb_DoorService;
import com.yyy.serviceImpl.Tb_DoorServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

@Controller
public class Tb_DoorController {
    @Autowired
    Tb_DoorService tb_doorService;
    /*该方法用来测试ssm框架的连通性*/
    @RequestMapping("/test1")
    public String  test(){
        List<tb_door> all = tb_doorService.findAll();
        for(tb_door item:all){
            System.out.println(item.toString());
        }
        return "test";
    }

    //万能跳转页面
    @RequestMapping("/{page}")
    public String all(@PathVariable String page){
        return page;
    }

    //打开主界面并展示所有的门店信息
    @RequestMapping("doorList")
    public String indexPage(Model mode1){
        List<tb_door> all = tb_doorService.findAll();
        mode1.addAttribute("list",all);
        return "door_list";
    }
    //新增一条门店记录
    @RequestMapping("doorAdd")
    public String  doorAdd(tb_door td){
        int i = tb_doorService.insertOne(td);
        return "redirect:/doorList";
    }
    //根据id查询记录，并将信息存储到model中

    //修改门店记录
    @RequestMapping("doorUpdate")
    public String doorUpdate(tb_door td){
        tb_doorService.updateById(td);
        return "redirect:/doorList";
    }

    //打开修改门店信息界面，并将查询到的信息填充进去
    @RequestMapping("doorInfo")
    public String doorInfo(Integer id,Model model){
        tb_door tb_door = tb_doorService.selectById(id);
        model.addAttribute("door",tb_door);
        return  "door_update";
    }
    //根据id删除记录
    @RequestMapping("doorDelete")
    public String doorDelete(Integer id){
        tb_doorService.deleteById(id);
        return "redirect:/doorList";
    }

}
